<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          
          <a-col :span="24">
            <a-form-model-item  label="报修名称" :labelCol="labelCol" :wrapperCol="wrapperCol"
              prop="faultRepairName">
              <a-input v-model="model.faultRepairName" placeholder="请输入报修名称" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="报修单号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="faultRepairNo">
              <a-input v-model="model.faultRepairNo" placeholder="请输入报修单号" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="设备ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="faultRepairDeviceId">
              <j-search-select-tag v-model="model.faultRepairDeviceId" dict="ene_device,device_name,id"  />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="故障等级ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="faultRepairLevelId">
              <j-search-select-tag v-model="model.faultRepairLevelId" dict="ene_fault_level,fault_level_name,id"
                 />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="故障类型ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="faultRepairTypeId">
              <j-search-select-tag v-model="model.faultRepairTypeId" dict="ene_fault_type,fault_type_name,id"
                 />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="故障时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="faultRepairTime">
              <j-date placeholder="请选择故障时间" v-model="model.faultRepairTime" :show-time="true" 
                date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="是否停机" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="faultRepairIsStop">
              <j-switch v-model="model.faultRepairIsStop" ></j-switch>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="故障图片" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="faultRepairImages">
              <j-image-upload isMultiple v-model="model.faultRepairImages" ></j-image-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="故障描述" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="faultRepairRemarks">
              <a-input v-model="model.faultRepairRemarks" placeholder="请输入故障描述" ></a-input>
            </a-form-model-item>
          </a-col>
          <!-- <a-col :span="24">
            <a-form-model-item label="故障报修状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="faultRepairState">
              <j-search-select-tag v-model="model.faultRepairState"
                dict="ene_fault_repair_state,fault_repair_state_name,id" />
            </a-form-model-item>
          </a-col> -->
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

import { httpAction, getAction } from '@/api/manage'
import { validateDuplicateValue } from '@/utils/util'

export default {
  name: 'EneFaultRepairSupplyForm',
  components: {
  },
  props: {
    disabled: {
      type: Boolean,
      default: false,
      required: false
    }
  },
  data() {
    return {
      model: {
      },
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      confirmLoading: false,
      validatorRules: {
        faultRepairName: [
          { required: true, message: '请输入报修名称!' },
        ],
        faultRepairNo: [
          { required: true, message: '请输入报修单号!' },
        ],
        faultRepairDeviceId: [
          { required: true, message: '请输入设备ID!' },
        ],
        faultRepairLevelId: [
          { required: true, message: '请输入故障等级ID!' },
        ],
        faultRepairTypeId: [
          { required: true, message: '请输入故障类型ID!' },
        ],
        faultRepairTime: [
          { required: true, message: '请输入故障时间!' },
        ]
      },
      url: {
        //add: "/repair/eneFaultRepair/add",
        edit: "/repair/eneFaultRepair/supply",
        queryById: "/repair/eneFaultRepair/queryById"
      }
    }
  },
  computed: {
    formDisabled() {
      return this.disabled
    },
  },
  created() {
    //备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model));
  },
  methods: {
    check(record) {
      this.model = Object.assign({}, record);
      this.visible = true;
    },
    submitForm() {
      const that = this;
      // 触发表单验证
      this.$refs.form.validate(valid => {
        if (valid) {
          that.confirmLoading = true;
          let httpurl = '';
          let method = '';
         
            httpurl += this.url.edit;
            method = 'put';
          httpAction(httpurl, this.model, method).then((res) => {
            if (res.success) {
              that.$message.success(res.message);
              that.$emit('ok');
            } else {
              that.$message.warning(res.message);
            }
          }).finally(() => {
            that.confirmLoading = false;
          })
        }

      })
    },
  }
}
</script>
<style scoped lang="less">
.ant-form-item {
  margin-bottom: 5px !important;
}
</style>